Skip to main content

yToggle

ybutton

Description

The yToggle component is a versatile UI element designed for toggling between two states, such as on/off or true/false. It provides an intuitive way for users to make binary choices with a simple click or tap. The yToggle is perfect for:

  • adjusting settings and preferences
  • any scenario where a binary choice is appropriate.

Basic Structure

The basic structure of the yToggle includes a track and a thumb. The track serves as the background over which the thumb slides, indicating the current state. Optionally, labels can be added to either side of the toggle to represent the states or provide additional information.

Track

The track can be styled individually and will serve as the background of the toggles main element.

Slide

The slide is the toggles indicator for the state.

Label

The label can display a title and will tell the user what the toggle is used for. There can be either a label on the left or on the right or both. These labels cannot be configured individually, but together at the same time.

Properties

Through its various properties the yToggle can be configured to suit your needs. The display below provides you with an overview of all the yToggle properties.

Properties can be changed directly through three methods:

  • Inside the Toolbar, which is positioned in your workarea next to your component where you need it. It shows the most important properties, thus providing a fast and efficient way to configure your component in the most basic way.
  • It may also occur in the Toolbar Extension, which is a seamless extension accesible as a dropdown item of the Toolbar. It extends the functionality of the Toolbar by providing advanced pickers for most used properties.
  • Inside the Detail Panel, which is located in the righthand drawer. Every property of a component can be configured here.
METAread more
--y-toggle__component-id

The identifier of the component that is unique within a page.

--y-toggle__component-type

The type of the component. For this component it is -toggle.

--y-toggle__name

The custom name of the component. It serves for better identification of the component.

--y-toggle__version

The custom version of the Toggle-component. This can be used to ensure that all components work well together.

--y-toggle__core-theme

The CoreTheme, which will be apllied to the Toggle. For further information on themes visit the themes page.

--y-toggle__sub-theme

The subtheme subordinated to the previously specified CoreTheme, which will be apllied to the Toggle. For further information on themes visit the themes page.

--y-toggle__group-theme

The group theme is a further variation of the subtheme which is specified especially for variations of a component inside the subtheme. For further information on themes visit the Theme-Manager page.

DISPLAYread more
--y-toggle__display

This property specifies the display behavior of the component. This can be be set to:

  • none
  • block
  • flex
  • inline
--y-toggle__position

This property specifies the type of positioning method used for the component. This can be be set to:

  • static
  • relative
  • absolute
  • sticky
  • fixed
--y-toggle__visible

This property can toggle the visibility of the component. The two modes are completely hidden and fully shown.

SIZEread more
--y-toggle__min-width

The minimum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-toggle__min-height

The minimum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-toggle__width

The value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-toggle__height

The value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-toggle__max-width

The maximum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-toggle__max-height

The maximum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-toggle__flex

The flex property sets the length on flexible items. This sets the value in n-fold shares extrapolated to all other components with the flex display within the same container.

PLACEMENTread more
--y-toggle__margin-top

This property creates a space around the component, outside of the top border. This can be set in percent or pixels.

--y-toggle__margin-right

This property creates a space around the component, outside of the right border. This can be set in percent or pixels.

--y-toggle__margin-bottom

This property creates a space around the component, outside of the bottom border. This can be set in percent or pixels.

--y-toggle__margin-left

This property creates a space around the component, outside of the left border. This can be set in percent or pixels.

--y-toggle__padding-top

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

--y-toggle__padding-right

This property creates a space within the component, inside of the right border. This can be set in percent or pixels.

--y-toggle__padding-bottom

This property creates a space within the component, inside of the bottom border. This can be set in percent or pixels.

--y-toggle__padding-left

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

Usage

In this section you'll find a collection of application scenarios and examples that illustrate how to leverage the yToggle in ways that deviate from its standard behavior, as defined by yBase. This section aims to inspire and guide you through various possibilities, helping you to implement more complex or unique functionalities tailored to your specific needs. General properties that are universally applicable can be found in the yBase usage section.

Variations

Toggle Elevated
Toggle Flat
Toggle Outlined
Toggle Rounded
Toggle Plain
genericsizeminWidth95px
genericsizeheight30px
stylebackgroundbgColor__normal#44ddbb
styleshadowboxShadow__normal0 3px 6px 0 rgba(16, 18, 24, 0.2)
styleborderborderRadius8px
stylelabellabel__fontColor__normal#FFFFFF
styletracktrackOff__color__normal#FFFFFF
styletracktrackOn__color__normal#FFFFFF
stylethumbthumbOff__color__normal#44ddbb
stylethumbthumbOn__color__normal#44ddbb

Thumb Styling

Toggle Traffic Light
Toggle Neutral
Toggle Dark Mode
genericsizeminWidth70px
styletracktrackOn__color#4CAF50
styletracktrackOff__color#F44336
stylethumbthumbOn__color#FFFFFF
stylethumbthumbOff__color#FFFFFF

Label Positioning

Toggle Label Left
Toggle Label Right
Toggle Label Both
genericsizeminWidth70px
stylelabelleftLabel'left'

Setting the yToggle Value

The yToggle component's value can be dynamically assigned either programmatically via JavaScript or by establishing a link to another component's value—known as a SourceLink. This flexibility allows the yToggle to respond to user interactions or application states in real time.

Via JavaScript

To set the yToggle's value using JavaScript, access the value property within the "style" > "thumb" category. This method is ideal for changing the yToggle's state based on user interactions or other events within your application.

Here’s how you can set the value in JavaScript:

Toggle EvtClicked
// function onToggle_1_EvtClicked (apiObject, component, eventData) {
const desiredValue = true; // true or false
component.set("style", "thumb", "value", desiredValue);
// }

Simply replace desiredValue with the appropriate boolean or comparable value that corresponds to the yToggle's position.

To link the yToggle’s value with another component, use the SourceLink Picker. This feature binds the yToggle’s state to another component's value, allowing for integrated component behavior.

Navigate to the SourceLink Picker section in the property settings and select the component you wish to link with. Once configured, the style > thumb > value of the yToggle will reflect the value provided by the linked component, ensuring synchronized states across related UI elements.

This dual approach to value assignment provides a robust solution for managing the yToggle’s state and integrating it seamlessly within your application’s logic flow.

Alternatively use the SourceLink Picker in the Toolbar as a Toolbar Extension.

Actions based on the State

A custom JavaScript function can be attached to the yToggle to perform an action based on its state. Here’s an example that logs the state to the console:

Button EvtClicked
// function onButton_1_EvtClicked (apiObject, component, eventData) {
const toggleState = component.get("style", "thumb", "value");
console.log(`The toggle is now ${toggleState ? "ON" : "OFF"}.`);
// }

Special Picker

There is a special picker for the yToggle in the Toolbar as a Toolbar Extension which will be used to link the component to a logic of 2 or more other components. This is a kind of SourceLink Picker, similar to other SourceLink Pickers to be found in other components.